package com.oig.sys.workflow.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.oig.common.validator.EnumValue;
import com.oig.common.validator.GroupAdd;
import com.oig.common.validator.GroupEdit;
import com.oig.sys.workflow.constants.JobEnums;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.media.Schema;

import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;

@Schema
@Data
public class CronJobDto {

	@Schema(description = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
	@NotNull(message = "参数错误,任务id不能为空", groups= {GroupEdit.class})
	private Integer id;

	@Schema(description = "任务名", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
	@NotEmpty(message = "参数错误,任务名不能为空", groups= {GroupAdd.class, GroupEdit.class})
	private String jobName;

	@Schema(description = "cron表达式", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
	@NotEmpty(message = "参数错误,cron表达式不能为空", groups= {GroupAdd.class, GroupEdit.class})
	private String scheduleCron;

	@Schema(description = "是否启用0-未启用 1-启用,1-立即加入调度")
	private String enable;

	@Schema(description = "任务类型,枚举： 01-HTTP", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
	@NotEmpty(message = "参数错误,任务类型不能为空", groups= {GroupAdd.class, GroupEdit.class})
	@EnumValue(message = "数据过滤类型值不正确",enumClass = JobEnums.JobType.class, enumValidMethod = "validCode", groups={GroupAdd.class, GroupEdit.class})
	private String jobType;

	@Schema(description = "任务配置,http任务配置 {\"url\":\"执行接口\",\"method\":\"get\",\"header\":[{\"name\":\"\",\"value\":\"\"}],\"body\":{}}", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
	@NotEmpty(message = "参数错误,任务配置不能为空", groups= {GroupAdd.class, GroupEdit.class})
	@Length(min = 3,message = "任务配置错误", groups= {GroupAdd.class, GroupEdit.class})
	private String sourceCfg;

	@Schema(description = "执行动作,枚举数组，暂时 1-通知,2-web_hook")
	private List<String> finishOpts;

	@Schema(description = "web_hook,预留")
	private String webHook;

	@Schema(description = "通知标题,通知标题")
	private String notifyTitle;
	@Schema(description = "通知内容,是否需要加占位符来处理数据？")
	private String notifyContent;
	@Schema(description = "消息类型 01-定向通知 02-群消息")
	private String notifyType;
	@Schema(description = "推送渠道id")
	private Integer pushChannelId;
	@Schema(description = "推送机器人（渠道名称）")
	private String pushChannelName;
	@Schema(description = "接收人类型")
	private String receiverType;
	@Schema(description = "接收人id")
	private Integer receiverId;
	@Schema(description = "接收人名称")
	private String receiverName;
	@Schema(description = "任务结果是否生成附件,只有http返回列表，或者sql返回list才生成文件")
	private String notifyResFile;

	@Schema(description = "所属租户id")
	private Integer tenantId;
	@Schema(description = "所属租户名称")
	private String tenantName;

	@Hidden
	@Schema(description = "创建人id")
	private Integer createUserId;
	@Hidden
	@Schema(description = "创建人")
	private String createUserName;
	@Hidden
	@Schema(description = "创建时间")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date createTime;
	@Hidden
	@Schema(description = "最后更新人id")
	private Integer lastUpdateId;
	@Hidden
	@Schema(description = "最后更新人")
	private String lastUpdateName;
	@Hidden
	@Schema(description = "最后更新时间")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date lastUpdateTime;

}
